package app.kits;

import app.models.activity.MallActivity;
import app.models.activity.BrandActivity;
import com.github.sog.libs.AppFunc;
import com.github.sog.plugin.sqlinxml.SqlKit;
import com.jfinal.plugin.ehcache.CacheKit;

import java.util.List;

/**
 * <p>
 * .
 * </p>
 *
 * @author liuhui
 * @version 1.0 14-5-3 下午2:12
 */
public class JobEhcacheKit {
    /**
     * 品牌活动的cacheName
     */
    public static final String BRAND_ACTIVITY_CACHE_NAME ="brandActivityCache";
    /**
     * 商场活动的cacheName
     */
    public static final String MALL_ACTIVITY_CACHE_NAME ="mallActivityCache";
    /**
     * 品牌活动cacheKey
     */
    public static final String BRAND_ACTIVITY_KEY="brandactivity";
    /**
     * 商场活动cacheKey
     */
    public static final String MALL_ACTIVITY_KEY="mallactivity";

    public static void init() {
        activity();
    }


    /**
     * 初始化活动数据到ehcache
     */
    private static void activity(){
        List<MallActivity> mallActivityList = MallActivity.dao.find(SqlKit.sql("mallactivity.list"));
        List<BrandActivity> brandActivityList = BrandActivity.dao.find(SqlKit.sql("brandactivity.list"));
        for (BrandActivity brandActivity : brandActivityList) {
            CacheKit.put(BRAND_ACTIVITY_CACHE_NAME,BRAND_ACTIVITY_KEY+ brandActivity.get(AppFunc.TABLE_PK_COLUMN),brandActivity);
        }
        for (MallActivity mallActivity : mallActivityList) {
            CacheKit.put(MALL_ACTIVITY_CACHE_NAME,MALL_ACTIVITY_KEY+mallActivity.get(AppFunc.TABLE_PK_COLUMN),mallActivity);
        }
    }
}
